package com.dragon.utilslibrary.network.http;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * 请求封装
 * @author king.liangjinshui
 *
 */
public class HttpRequest {
	private String Content_Type = "application/x-www-form-urlencoded";//"text/json;charset=utf-8";//
	private String url;
	private HttpMethod httpMethod;
	private File downloadFile;//下载的文件
//	private File uploadFile;//上传的文件

	private boolean useCaches;//是否使用缓存

	private Map<String, File> fileparams = new HashMap<String, File>();
	private HashMap<String, Object> paremMap = new HashMap<String, Object>();
	private int timeOut = -1;

	public int getTimeOut() {
		return timeOut;
	}
	/**
	 * 设置超时时长
	 * @param timeOut
	 */
	public void setTimeOut(int timeOut) {
		this.timeOut = timeOut;
	}
	public String getUrl() {
		return url;
	}
	/**
	 * 设置请求地址
	 * @param url
	 */
	public void setUrl(String url) {
		this.url = url;
	}
	public HttpMethod getHttpMethod() {
		return httpMethod;
	}
	/**
	 * 设置请求方式，get、post
	 * @param httpMethod
	 */
	public void setHttpMethod(HttpMethod httpMethod) {
		this.httpMethod = httpMethod;
	}

	public File getDownloadFile() {
		return downloadFile;
	}
	/**
	 * 设置文件下载的参数，路径
	 * @param downloadFile
	 */
	public void setDownloadFile(File downloadFile) {
		this.downloadFile = downloadFile;
	}
	//封装请求参数给http
	public String getParems(){
		StringBuffer sb = new StringBuffer();
		if(paremMap != null && !paremMap.isEmpty()){
			Set<String> keys = paremMap.keySet();
			for (String s : keys) {
				sb.append(s).append("=").append(paremMap.get(s)).append("&");
			}
			sb.deleteCharAt(sb.length() - 1);
		}
		return sb.toString();
	}
	/**
	 * 添加请求参数
	 * @param key
	 * @param value
	 */
	public void addParems(String key, String value){
		paremMap.put(key, value);
	}
	public void addParems(String key, int value){
		paremMap.put(key, value);
	}
	public void addParems(String key, long value){
		paremMap.put(key, value);
	}
	/**
	 * 添加文件上传的文件
	 * @param key
	 * @param file
	 */
	public void addFileParems(String key, File file){
		fileparams.put(key, file);
	}
	/**
	 * 文件上传时的文件
	 * @return
	 */
	public Map<String, File> getFileParems(){
		return fileparams;
	}
	/**
	 * 文件上传时的参数
	 * @return
	 */
	public HashMap<String, Object> getFileStringParens(){
		return paremMap;
	}
	/**
	 * 设置Content_Type
	 * 默认application/x-www-form-urlencoded
	 * @return
	 */
	public String getContent_Type() {
		return Content_Type;
	}
	public void setContent_Type(String content_Type) {
		Content_Type = content_Type;
	}
	public boolean isUseCaches() {
		return useCaches;
	}
	/**是否使用缓存*/
	public void setUseCaches(boolean useCaches) {
		this.useCaches = useCaches;
	}

//	public File getUploadFile() {
//		return uploadFile;
//	}
//	public void setUploadFile(File uploadFile) {
//		this.uploadFile = uploadFile;
//	}

}
